import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  token: string;
}
export function login(data: LoginData) {
  return axios.post<LoginRes>('/api/user/login', data);
}

export function logout() {
  return axios.post<LoginRes>('/api/user/logout');
}

export function getUserInfo() {
  return axios.post<UserState>('/api/user/info');
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}



export const getUserList = async (params) => {
  const response = await axios.post(`/demandUser/getList`, {
    page:params.current,
    size:params.pageSize,
    condition: {...params},
  });
  return response;
};

export const deleteUser = async (id: number) => {
  const response = await axios.post(`/demandUser/delete`, { id });
  return response.data;
};

export const getUserDetail = async (id: number) => {
  const response = await axios.get(`/demandUser/getDetail`, {
    params: { id },
  });
  return response.data;
};

export const saveUser = async (user: any) => {
  const response = await axios.post(`/demandUser/saveUser`, user);
  return response.data;
};
